<template>
  <div>
    <van-button
      style="position: fixed; top: 30px; right: 0; z-index: 999"
      type="primary"
      >loading:{{ loading }}===finished:{{ finished }}===按钮</van-button
    >
    <van-list
      :finished="finished"
      @load="onLoad"
      finished-text="我是有底线的"
      v-model="loading"
    >
      <van-cell :key="index" :title="item" v-for="(item, index) in list" />
    </van-list>
  </div>
</template>
<script>
export default {
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
    };
  },
  methods: {
    onLoad () {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      // console.log(this.onLoad);
      // setTimeout(() => {
      //   for (let i = 0; i < 30; i++) {
      //     this.list.push(this.list.length + 1);
      //   }

      //   // 加载状态结束
      //   this.loading = false;

      //   // 数据全部加载完成
      //   if (this.list.length >= 40) {
      //     this.finished = true;
      //   }
      // }, 1000);

      if (this.list.length > 50) {
        this.finished = true//结束上拉，设置值为true就表示不能上拉了
        return
      }

      setTimeout(() => {
        for (var i = 0; i < 20; i++) {
          this.list.push(this.list.length + 1)
        }

        this.loading = false// 结束当前加载
      }, 3000)
    },
  },
};
</script>
<style lang='less'  scoped>
</style>
